package com.zhima.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.zhima.enums.ScoreStrategy;
import com.zhima.util.ScoreUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import static com.zhima.constant.TestCaseConstant.*;

/**
 * @author : 芝麻
 * 测评模板类，即测评点信息
 * @date : 2023-08-26 16:15
 **/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class TestCaseTemplate implements Serializable {
    private Integer index;
    private Integer maxTimeLimit;
    private Integer maxMemoryLimit;
    private Integer score;
    private Integer subTaskIndex;
    private ScoreStrategy scoreStrategy;
    /**
     * 如果是SPJ，需要保存评测文件id
     */
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Long spjFileId;

    public static List<TestCaseTemplate> initNTestCaseTemplates(int n) {
        List<TestCaseTemplate> testCaseTemplates = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            testCaseTemplates.add(new TestCaseTemplate(
                    i,
                    DEFAULT_MAX_TIME_LIMIT,
                    DEFAULT_MAX_MEMORY_LIMIT,
                    ScoreUtil.getScore(i, n),
                    DEFAULT_SUB_TASK_INDEX,
                    // 默认计分策略是总和
                    ScoreStrategy.SUM,
                    null
            ));
        }
        return testCaseTemplates;
    }
}